<?php


function form_pengecualian($id ){
	 
	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);

	my_set_file_js(
		array(
			'components/system/jquery/autocomplete/jquery.autocomplete.js'  
		)
	);
	my_set_file_css(
		array(
				'components/system/jquery/autocomplete/jquery.autocomplete.css' 
			)
	);

	my_set_code_js('  
		function findValue(li) {
			if( li == null ) return alert("No match!"); 
			if( !!li.extra ) var sValue = li.extra[0]; 
			else var sValue = li.selectValue;
		}

		function selectItem(li) {
			findValue(li);
		}

		function formatItem(row) {
			return   row[0] ;
		}

		function lookupAjax(){
			var oSuggest = $("#nama_karyawan")[0].autocompleter;
			oSuggest.findValue(); 
			return false;
		}
		$(document).ready(function() {
			$("#nama_karyawan").autocomplete(
				"autocomplete_daftar_karyawan.php",
				{
					delay:10,
					minChars:2,
					matchSubset:1,
					matchContains:1,
					cacheLength:5,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
					autoFill:true
				}
			);
			 
		});

		function checkName(name){
			$.get("check_karyawan_names.php", { nama: name  },
			   function(data){
				 if(data ==  \'0\' ){
					alert(\'Nama karyawan \'+ name+\' tidak ditemukan\nHarap diperiksa kembali\');
					$(\'#nama_karyawan\').val(\'\');
					return false;
				 } 
			   });
		}
	');	
	  
	$view  = form_header( "detail pegawai" , "cp"  );

	$karyawan = array(
		'name'=>'nama_karyawan',
		'value'=>(  $_POST['nama_karyawan']    ),
		'id'=>'nama_karyawan',
		'type'=>'textfield',
		'size'=>'45'
	);
	$form_karyawan = form_dynamic($karyawan);
	$view .= form_field_display( $form_karyawan  , "<b>NIK/Nama Kary.</b>"  );
	

	$gaji_baru = array(
		'name'=>'gaji_baru',
		'value'=>(isset($_POST['gaji_baru'])? $_POST['gaji_baru'] :   '' ),
		'id'=>'gaji_baru',
		'type'=>'textfield',
		'size'=>'45'
	);
	$form_gaji_baru = form_dynamic($gaji_baru);
	$view .= form_field_display( $form_gaji_baru  , "<b>Gaji baru.</b>"  );	
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	
	return $view;
}

function submit_pengecualian($id){
	$karyawan_id =  check_karyawan_by_nik_nama($_POST['nama_karyawan']); 
	$query = "DELETE FROM pr_kenaikan_gaji_karyawan WHERE karyawan_id = {$karyawan_id} AND kenaikan_gaji_id={$id} ";
	my_query($query);
	$kekaryawanan = my_get_data_by_id('kekaryawanan','karyawan_id',$karyawan_id);
	$datas = array(
			'kenaikan_gaji_id'=>my_type_data_int($id),
			'karyawan_id'=>my_type_data_int($karyawan_id),
			'grade_id'=>my_type_data_int($kekaryawanan['grade_id']),
			'gaji_lama'=>my_type_data_str( $kekaryawanan['gapok_km'] ), 			
			'adj'=>my_type_data_str( '' ), 			
			'pa'=>my_type_data_str( '' ), 			
			'mark2'=>my_type_data_str( 'TP' ), 			
			'gb_pa'=>my_type_data_str('' ), 			
			'lumps'=>my_type_data_str( 0 ), 			
			'gaji_baru'=>my_type_data_str( $_POST['gaji_baru'] ), 
		);
		my_insert_record('pr_kenaikan_gaji_karyawan' , $datas);	
		$datas2 = array(
			'gapok_km'	=> my_type_data_str($gapok_br)
		);
		
		return my_update_record(	'kekaryawanan'  ,	'karyawan_id'	,	$karyawan_id	,	$datas2 ); 
}